load("@rules_gazebo//gazebo:headers.bzl", "gz_export_header")

package(
    default_applicable_licenses = ["//:license"],
    features = [
        "layering_check",
        "parse_headers",
    ],
)

public_headers_no_gen = glob([
    "include/gz/common/*.hh",
    "include/gz/common/**/*.hh",
])

sources = glob(
    include = ["src/*.cc"],
    exclude = ["src/*_TEST.cc"],
)

test_sources = glob(["src/*_TEST.cc"])

gz_export_header(
    name = "Export",
    out = "include/gz/common/io/Export.hh",
    export_base = "GZ_COMMON_IO",
    lib_name = "gz-common-io",
)

public_headers = public_headers_no_gen + [
    "include/gz/common/io/Export.hh",
]

cc_library(
    name = "io",
    srcs = sources,
    hdrs = public_headers,
    copts = [
        "-fexceptions",
    ],
    includes = ["include"],
    visibility = ["//visibility:public"],
    deps = [
        "//:gz-common",
        "@gz-math",
        "@gz-utils//:ImplPtr",
    ],
)

[cc_test(
    name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
    srcs = [src],
    env = {
        "GZ_BAZEL": "1",
    },
    deps = [
        ":io",
        "//:gz-common",
        "//testing",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
        "@gz-math",
    ],
) for src in test_sources]
